package com.ijava.util;

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class EncryptionUtil {
	private static final String MD5 = "MD5";

	public static String md5(String source) throws Exception {
		String md5 = source;
		try {
			MessageDigest messageDigest = MessageDigest.getInstance(MD5);
			messageDigest.reset();
			messageDigest.update(source.getBytes("UTF-8"));
			md5 = new BigInteger(1,messageDigest.digest()).toString(16);
		} catch (NoSuchAlgorithmException e) {
			throw e;
		} catch (UnsupportedEncodingException e) {
			throw e;
		} catch (Exception e){
			throw e;
		}
		return md5;
	}

}
